package com.base.home.presenter;

import android.app.Activity;
import android.text.TextUtils;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.bean.TabEntity;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.home.bean.ConcertSelectEntity;
import com.base.home.view.TabManagerView;

import java.util.HashMap;
import java.util.List;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2020/2/17.
 */

public class TabManagerPresenter extends BasePresenter<TabManagerView>{
    public TabManagerPresenter(TabManagerView view, Activity activity) {
        super(view, activity);
    }


    @Override
    public void start() {
        super.start();
        initTab();
    }

    public void initTab(){
        mView.showPb_mes("正在初始化");
        HashMap<String, Object> param = new HashMap<>();
        Disposable disposable = RealNetWorkUtil.get()
                .method("api-train/app/categoryTree")
                .params(param)
                .build().enqueue(TabEntity.class, new CallBackImpl<TabEntity>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        if (!TextUtils.isEmpty(msg)) {
                            mView.showMes(msg);
                        }
                    }
                    @Override
                    public void onNext(TabEntity entities) {
                        mView.returnTabList(entities);
                        mView.hidePb_mes();
                    }
                });
        mCompositeDisposable.add(disposable);
    }

    public void saveTab(final List<TabEntity.SavedBean> list){
        for (int i=0;i<list.size();i++){
            list.get(i).setSort(i);
        }
        mView.showPb_mes("正在保存");
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-train/app/saveMyCategoryList")
                .content(list)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        if (!TextUtils.isEmpty(msg)) {
                            mView.showMes(msg);
                        }
                    }
                    @Override
                    public void onNext(String str) {
                        mView.showMes("保存成功");
                        mView.returnSaveSuccess(list);
                        mView.hidePb_mes();
                    }
                });
        mCompositeDisposable.add(disposable);
    }
}
